package SoundManager
{
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.net.URLRequest;
	import flash.utils.Dictionary;
	import GameLogic.Game;
	import LoadUnit.LoadManager;
	public class SoundFactory
	{
		public static var Sounds:Dictionary = new Dictionary();
		public static var SoundLoadFinished:Boolean = false;
		
		private static var soundUrls:Vector.<String> = new Vector.<String>();
		private static var name:Vector.<String> = new Vector.<String>();
		private static var loadStop:Boolean = true;
		public function SoundFactory()
		{
		}
		
		public static function Init():void
		{
			var root:String = "Resource/sound/"
			soundUrls.push(root + "buqiang.mp3");
			name.push("buqiang");
			soundUrls.push(root + "buqiang2.mp3");
			name.push("buqiang");
			soundUrls.push(root + "button1.mp3");
			name.push("button1");
			soundUrls.push(root + "button2.mp3");
			name.push("button2");
			soundUrls.push(root + "guiyiyou.mp3");
			name.push("guiyiyou");
			soundUrls.push(root + "gun1.mp3");
			name.push("gun1");
			soundUrls.push(root + "gun2.mp3");
			name.push("gun2");
			soundUrls.push(root + "huojianfashe.mp3");
			name.push("huojianfashe");
			soundUrls.push(root + "jiaobu.mp3");
			name.push("jiaobu");
			soundUrls.push(root + "jiqiang.mp3");
			name.push("jiqiang");
			soundUrls.push(root + "mada.mp3");
			name.push("mada");
			soundUrls.push(root + "sound16.mp3");
			name.push("sound16");
			Load();
		}
		
		public static function Load():void
		{
			if (soundUrls.length > 0)
			{
			  var url:String = soundUrls.shift();
			  var request:URLRequest = new URLRequest(url);
			  var soundFactory:Sound = new Sound();
			  soundFactory.load(request);
			  
			  loadStop = true;
			  soundFactory.addEventListener(Event.COMPLETE, function(e:Event):void
			  {
				var namest:String = name.shift();
				Sounds[namest] = soundFactory;
				if (soundUrls.length > 0)
				{
				  loadStop = false;
			      Load();
				}
				else
				{
					var t:Dictionary = Sounds;
					SoundLoadFinished = true;
				}
			  });
			  soundFactory.addEventListener(ProgressEvent.PROGRESS, function(e:ProgressEvent):void
			  {
				  LoadManager.loadline.LoopAnimation(e);
			  });
			
			}
		}		
	}
}